/**
 * VerticalLetterAssembler.java | Created on 18 09 2010
 */
package com.pacm.assembler;

import com.pacm.letter.Letter;

/**
 * The vertical letter assembler implementation
 *
 * @author Paul Augustine C. Mendoza
 */
public class VerticalLetterAssembler implements LetterAssembler {

    private static final String LINE_FEED = "\n";

    private StringBuffer stringBuffer;
    private int size;

    public VerticalLetterAssembler() {
        stringBuffer = new StringBuffer();
    }

    public void assemble(Letter[] letters, int size) {
        this.size = size;
        for (Letter letter : letters) {
            populateStringBuffer(letter);
        }
    }

    public String getPrintableString() {
        return this.stringBuffer.toString();
    }

    private void populateStringBuffer(Letter letter) {
        for (String[] row : letter.getMatrix()) {
            processColumns(row);
            this.stringBuffer.append(LINE_FEED);
        }
    }

    private void processColumns(String[] row) {
        for (int j = 0; j < this.size; j++) {
            this.stringBuffer.append(row[j]);
        }
    }
}
